import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import '../models/auth_provider.dart';

class ProfileScreen extends StatelessWidget {
  const ProfileScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(54.h),
        child: AppBar(
          backgroundColor: Colors.white,
          elevation: 0,
          flexibleSpace: Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [Colors.white, Colors.orange.shade50, Colors.white],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                stops: [0.0, 0.6, 1.0],
              ),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                AppBar(
                  backgroundColor: Colors.transparent,
                  elevation: 0,
                  title: Text(
                    '我的',
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 24.sp,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  centerTitle: false,
                  actions: [
                    IconButton(
                      icon: Icon(Icons.settings),
                      onPressed: () {
                        // 设置按钮点击事件
                      },
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
      body: Container(
        color: Colors.white,
        child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Consumer<AuthProvider>(
              builder: (context, authProvider, child) {
                return Column(
                  children: <Widget>[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('欢迎来到金马短剧'),
                        TextButton(
                          onPressed: () {
                            if (authProvider.isLoggedIn) {
                              authProvider.logout();
                            } else {
                              Navigator.pushNamed(context, '/login');
                            }
                          },
                          child: Text(
                            authProvider.isLoggedIn ? '退出登录' : '立即登录',
                            style: TextStyle(color: Colors.red),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(height: 20.h),
                    GridView.count(
                      shrinkWrap: true,
                      crossAxisCount: 4,
                      children: [
                        Column(
                          children: [
                            Icon(Icons.history),
                            Text('浏览历史'),
                          ],
                        ),
                        Column(
                          children: [
                            Icon(Icons.favorite),
                            Text('我的收藏'),
                          ],
                        ),
                        Column(
                          children: [
                            Icon(Icons.notifications),
                            Text('系统通知'),
                          ],
                        ),
                        Column(
                          children: [
                            Icon(Icons.shopping_cart),
                            Text('商城'),
                          ],
                        ),
                      ],
                    ),
                    SizedBox(height: 20.h),
                    Text('常用功能', style: TextStyle(fontWeight: FontWeight.bold)),
                    GridView.count(
                      shrinkWrap: true,
                      crossAxisCount: 4,
                      children: [
                        Column(
                          children: [
                            Icon(Icons.book),
                            Text('笔记书籍'),
                          ],
                        ),
                        Column(
                          children: [
                            Icon(Icons.video_call),
                            Text('看直播'),
                          ],
                        ),
                        Column(
                          children: [
                            Icon(Icons.upload_file),
                            Text('上传视频'),
                          ],
                        ),
                        Column(
                          children: [
                            Icon(Icons.download),
                            Text('我的下载'),
                          ],
                        ),
                        Column(
                          children: [
                            Icon(Icons.feedback),
                            Text('反馈与帮助'),
                          ],
                        ),
                        Column(
                          children: [
                            Icon(Icons.account_circle),
                            Text('会员中心'),
                          ],
                        ),
                      ],
                    ),
                  ],
                );
              },
            ),
          ),
        ),
      ),
    );
  }
}
